<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/8/11
 * Time: 11:07
 */

namespace p5\objects;


class Counter
{

    protected $counters = [];

    public function __construct()
    {

    }

    public function increment($key, $size = 1)
    {
        $value = $size;
        if (array_key_exists($key, $this->counters)) {
            $value = $this->counters[$key] * 1 + $size;
        }
        $this->counters[$key] = $value;
        return $value;
    }

    public function decrement($key, $size = -1)
    {
        return $this->increment($key, $size);
    }

    public function get($key)
    {
        if (array_key_exists($key, $this->counters)) {
            return $this->counters[$key];
        }
        return 0;
    }

    public function all()
    {
        return $this->counters;
    }

}